﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class AddCategory : System.Web.UI.UserControl
    {
        public int intactivetop, intactiveleft;
        public string pathToCreate;
        public int idnextnew;
        public int ordinal;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAddNews_Click(object sender, EventArgs e)
        {
            int nextid = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.getNextID("tbl_CategoryTop", "CategoryTop_ID1"));
                if (txtName.Text != "")
                {
                    if (CKEditorNoidung.Text != "")
                    {
                            idnextnew = nextid + 1;
                            DataTable dt = DAL.DCollector.DBCollector.Instance.CallStored("callstored", "SELECT TOP 1 CategoryTop_Ordinal FROM tbl_CategoryTop ORDER BY CategoryTop_Ordinal DESC", true);
                            ordinal = Int32.Parse(dt.Rows[0]["CategoryTop_Ordinal"].ToString());
                            LIB.Validate saveimage = new LIB.Validate();
                            string EncodeNoidung = Server.HtmlEncode(CKEditorNoidung.Text);
                            string value = "" + idnextnew + ",N'" + txtName.Text + "',N'" + CKEditorNoidung.Text + "' , '" + ordinal + "'";
                            List<string> values = new List<string>();
                            values.Add(value);
                            DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_CategoryTop", "insertemployee", values, false);
                            Response.Redirect("/Index.aspx?panel=2&sub=1");
                    }
                    else
                    {
                        Response.Write("<script>alert('Vui lòng nhập tóm tắt nội dung')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('Bạn vui lòng nhập nội dung tin tức')</script>");
                }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            Response.Redirect("/Index.aspx?panel=2&sub=1");
        }
    }
}